<template>
	<view class="container">
		<view class="top">
			提示：选择行业会自动关联到爆款视频打造，且选择行业后不予修改，请确认好行业！若你的行业下方选择没有，请先选择其他行业，后续就行业上线后给予一个修改的机会。
		</view>
		<view class="ItemList">
			<div class="item" v-for="(item,index) in titleList" :key="index">
				<view class="title">
					{{item.title}}
				</view>
				<view class="ItemDetialList">
					<block v-if="item.jobList.length > 0">
						<view class="item" v-for="(ItemDetial,index) in item.jobList" v-for-item="ItemDetail" :key="index">
							<view class="itemDetial" :style="{ backgroundColor: id === ItemDetial.id ? 'rgb(1, 152, 213)' : '' }"
								:data-item="ItemDetial" :data-title="item.title" :data-id="item.id" @click="changeItem">
								<view class="img">
									<image :src="baseHttp+ItemDetial.pictureAddress" style="height: 100%; width: 100%;">
									</image>
								</view>
								<view class="title">
									{{ItemDetial.title}}
								</view>
							</view>
						</view>
					</block>
					<view class="" v-else
						style="height: 100%; width: 100%; display: flex; align-items: center; font-weight: bold; font-size: 30rpx;">
						暂无数据噢~！
					</view>
				</view>
			</div>
		</view>
		<view style="height: 130rpx;width:100%;">
		</view>
		<view class="BtnBottom">
			<button @click="cancel" style="color: bac;">取消</button>
			<button @click="enter" style="color: white;">确认</button>
		</view>
		
	</view>
</template>

<script>
	
	import Http from '../../utils/http';
	const http =new Http()
	export default {
		data() {
			return {
				titleList: [],
				baseHttp: '',
				id: null,
				obj:{}
			}
		},
		onLoad() {
			this.getList();
		},
		mounted() {
			const app = getApp()
			this.baseHttp = app.globalData.baseHttp; // 输出 '我是全局变量'
		},
		methods: {
			cancel(){
				uni.navigateTo({
					url:'/subpkg/createShop/createShop',
				})
			},
			enter(){
				if(this.obj.title && this.obj.item && this.obj.tradeId){		
					var pages = getCurrentPages();
					var prevPage = pages[pages.length - 2];
					//prevPage.$vm.otherFun(this.obj);
					uni.$emit('can',this.obj);
					uni.navigateBack();
				}else{
					uni.showToast({
						title: '选择不能为空',
						duration: 2000,
						icon:'error'
					});
				}
			},
			// 选择行业
			changeItem(e) {
				let data = e.currentTarget.dataset.item
				let title = e.currentTarget.dataset.title
				let trade = e.currentTarget.dataset.id
				this.id = data.id;
				this.obj = {
					title:title,
					item:data.title,
					tradeId:trade
				}
			},
			getList() {
				http.get('v1/system/trade/list').then(res=>{
					this.titleList = res.data.data;
					console.log(this.titleList);
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	.container {
		padding: 0 20rpx;
		background-color: rgb(240, 242, 255);
		min-height: 100vh;
		height: 100%;
		box-sizing: border-box;
		.top {
			font-size: 27rpx;
			color: red;
			font-weight: bold;
		}

		.ItemList {
			.item {
				margin: 10rpx 0rpx;

				.title {
					font-size: 40rpx;
					font-weight: bold;
					height: 70rpx;
					line-height: 70rpx;
				}

				.ItemDetialList {
					width: 100%;
					display: flex;
					margin: 10rpx 0rpx;
					flex-wrap: wrap;

					.item {
						height: 100%;
						width: 25%;
						padding: 10rpx;
						box-sizing: border-box;

						.itemDetial {
							display: flex;
							flex-direction: column;
							align-items: center;
							background-color: white;
							border-radius: 20rpx;

							.img {
								height: 130rpx;
								width: 130rpx;
								margin-top: 20rpx;
								border-radius: 20rpx;
								box-sizing: border-box;
							}

							.title {
								font-size: 25rpx;
							}
						}
					}
				}

			}
		}
		.BtnBottom{
			// width: 100vw;
			
			display: flex;
			position: fixed;
			bottom: 0px;
			left:0;
			right: 0;
			justify-content: space-between;
			margin-bottom: 10rpx;
			button{
				width: 45%;
				height: 100rpx;
				border-radius: 20rpx;
				background-color: #00008B;
			}
			button:first-child {
			    background-color: white /* 添加右侧间距 */
			}
		}
	}
</style>